<%@ page contentType="text/html;charset=UTF-8" language="java" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<html>
<head>
    <title>商城管理系统</title>
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap/css/bootstrap.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/iCheck/square/blue.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.min.css">
    <link rel="stylesheet" href="${pageContext.request.contextPath}/plugins/adminLTE/css/AdminLTE.css">
</head>

<body class="hold-transition skin-purple sidebar-mini">

<div class="wrapper">

    <%@include file="header.jsp"%>

    <%@include file="aside.jsp"%>

    <div class="content-wrapper">
        <section class="content-header">
            <h1>
                用户管理
                <small>用户列表</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#"><i class="fa fa-dashboard"></i> 首页</a></li>
                <li><a href="#">用户管理</a></li>
                <li class="active">用户列表</li>
            </ol>
        </section>

        <section class="content">

            <div class="box box-primary">
                <div class="box-header with-border">
                    <h3 class="box-title">列表</h3>
                </div>

                <div class="box-body">

                    <div class="table-box">

                        <div class="pull-left">
                            <div class="form-group form-inline">
                                <div class="btn-group">
                                    <button type="button" class="btn btn-default" title="新建" onclick="location.href='${pageContext.request.contextPath}/pages/manage/user-add.jsp'">
                                        <i class="fa fa-file-o"></i> 新建</button>
                                    <button type="button" class="btn btn-default" title="删除" onclick="deleteUser()"><i class="fa fa-trash-o"></i> 删除</button>
                                    <button type="button" class="btn btn-default" title="开启" onclick="openUser()"><i class="fa fa-check"></i> 开启</button>
                                    <button type="button" class="btn btn-default" title="屏蔽" onclick="closeUser()"><i class="fa fa-ban"></i> 屏蔽</button>
                                    <button type="button" class="btn btn-default" title="刷新" onclick="location.href='${pageContext.request.contextPath}/user/searchuser?page=1&size=${pageInfo.pageSize}&keyword=${param.keyword}'"><i class="fa fa-refresh"></i> 刷新</button>
                                </div>
                            </div>
                        </div>
                        <div class="box-tools pull-right">
                            <div class="input-group" style="width: 300px;">
                                <c:if test="${empty param.keyword}">
                                <input type="text" name="search" class="form-control" placeholder="搜索" id="searchuser">
                                </c:if>
                                <c:if test="${not empty param.keyword}">
                                    <input type="text" name="search" class="form-control" value="${param.keyword}" id="searchuser">
                                </c:if>
                                <div class="input-group-btn" style="width: 30px;">
                                    <button type="submit" name="submit" class="btn btn-facebook btn-flat"  id="search"><i class="fa fa-search"></i>
                                    </button>
                                </div>
                            </div>
                        </div>

                        <table id="dataList" class="table table-bordered table-striped table-hover dataTable">
                            <thead>
                            <tr>
                                <th class="" style="padding-right:0px;">
                                <input id="selall" type="checkbox" class="icheckbox_square-blue">
                            </th>
                                <th class="sorting">ID</th>
                                <th class="sorting">用户名</th>
                                <th class="sorting">密码</th>
                                <th class="sorting">昵称</th>
                                <th class="sorting">状态</th>
                                <th class="text-center">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            <c:if test="${not empty pageInfo.list }">
                            <c:forEach items="${pageInfo.list}" var="user">
                            <tr>
                                <td><input name="ids" type="checkbox" class="checkb" value="${user.id }"></td>
                                <td>${user.id}</td>
                                <td>${user.user_Name}</td>
                                <td>${user.user_Password}</td>
                                <td>${user.user_Nickname}</td>
                                <td>${user.user_Status_str}</td>
                                <td class="text-center">
                                    <button type="button" class="btn bg-olive btn-xs" >详情</button>
                                    <button type="button" class="btn bg-olive btn-xs" onclick="location.href='${pageContext.request.contextPath}/user/findById?id=${user.id}'">编辑</button>
                                </td>
                            </tr>
                        </c:forEach>
                        </c:if>
                            </tbody>
                        </table>
                        <c:if test="${empty pageInfo.list }">
                            <div class="alert alert-warning text-center my-5 py-5 col-12  col-md-12 offset-md-6" role="alert">
                                没有任何符合条件的用户信息
                            </div>
                        </c:if>


                    </div>


                </div>
                <div class="box-footer">
                    <div class="pull-left">
                        <div class="form-group form-inline">
                            总共${pageInfo.pages}页，共${pageInfo.total}条数据。 每页
                            <select class="form-control" id="changePageSize" name="choose" onchange="changePageSize()">
                                <option>${pageInfo.pageSize}</option>
                                <c:forEach begin="1" end="10" var="pageSize">
                                    <option>${pageSize}</option>
                                </c:forEach>
                            </select> 条
                        </div>
                    </div>

                    <div class="box-tools pull-right">
                        <ul class="pagination">
                            <li>
                                <a href="${pageContext.request.contextPath}/user/searchuser?page=1&size=${pageInfo.pageSize}&keyword=${param.keyword}" aria-label="Previous" >首页</a>
                            </li>
                            <li><a href="${pageContext.request.contextPath}/user/searchuser?page=${pageInfo.pageNum-1}&size=${pageInfo.pageSize}&keyword=${param.keyword}">上一页</a></li>
                            <c:forEach begin="1" end="${pageInfo.pages}" var="pageNum">
                                <li><a href="${pageContext.request.contextPath}/user/searchuser?page=${pageNum}&keyword=${param.keyword}&size=${pageInfo.pageSize}">${pageNum}</a></li>
                            </c:forEach>

                            <li><a href="${pageContext.request.contextPath}/user/searchuser?page=${pageInfo.pageNum+1}&size=${pageInfo.pageSize}&keyword=${param.keyword}">下一页</a></li>
                            <li>
                                <a href="${pageContext.request.contextPath}/user/searchuser?page=${pageInfo.pages}&size=${pageInfo.pageSize}&keyword=${param.keyword}" aria-label="Next">尾页</a>
                            </li>
                        </ul>
                    </div>
                </div>
            </div>
        </section>
    </div>
<script src="${pageContext.request.contextPath}/plugins/jQuery/jquery-2.2.3.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap/js/bootstrap.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/bootstrap-wysihtml5/bootstrap3-wysihtml5.all.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/iCheck/icheck.min.js"></script>
<script src="${pageContext.request.contextPath}/plugins/adminLTE/js/app.min.js"></script>
<script>

    function changePageSize(){
        var pagesize = $("#changePageSize").val();
        location.href="${pageContext.request.contextPath}/user/searchuser?page=1&keyword=${param.keyword}&size="+pagesize;
    }
    $('#search').click(function () {
        var keyword = $("#searchuser").val();
        location.href="${pageContext.request.contextPath}/user/searchuser?keyword="+keyword;
    });

    function deleteUser() {
        var result = "";
        var count = 0;
        $(".checkb").each(function () {
            if ($(this).is(':checked')) {
                result += $(this).val() + ",";
                count++;
            } else {
            }
        });
        if(count==0){
            alert('请选择用户');
            return;
        }
        else if (!confirm("确定删除这" + count + "位用户?")) {
            return;
        }
        location.href = "${pageContext.request.contextPath}/user/delmore?tag=" + result;

    }
    function openUser() {
        var result = "";
        var count = 0;
        $(".checkb").each(function () {
            if ($(this).is(':checked')) {
                result += $(this).val() + ",";
                count++;
            } else {
            }
        });
        if(count==0){
            alert('请选择用户');
            return;
        }
        else if (!confirm("确定开启这" + count + "位用户?")) {
            return;
        }
        location.href = "${pageContext.request.contextPath}/user/open?tag=" + result;

    }

    function closeUser() {
        var result = "";
        var count = 0;
        $(".checkb").each(function () {
            if ($(this).is(':checked')) {
                result += $(this).val() + ",";
                count++;
            } else {
            }
        });
        if(count==0){
            alert('请选择用户');
            return;
        } else if (!confirm("确定关闭这" + count + "位用户?")) {
            return;
        }
        location.href = "${pageContext.request.contextPath}/user/close?tag=" + result;
    }

    function choose(){
      var id = $("#choose").val();
    }
    $(document).ready(function() {
        $(".textarea").wysihtml5({
            locale: 'zh-CN'
        });
    });

    $(document).ready(function() {
        setSidebarActive("user-setting");

        $("#dataList td input[type='checkbox']").iCheck({
            checkboxClass: 'icheckbox_square-blue',
            increaseArea: '20%'
        });
        // 全选操作
        $("#selall").click(function() {
            var clicks = $(this).is(':checked');
            if (!clicks) {
                $("#dataList td input[type='checkbox']").iCheck("uncheck");
            } else {
                $("#dataList td input[type='checkbox']").iCheck("check");
            }
            $(this).data("clicks", !clicks);
        });
    });
</script>
</body>

</html>